package com.ruoyi.basedata.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.basedata.service.IBaseReportService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;

/**
 * 基础数据报表控制器
 * 
 * @author ruoyi
 */
@Controller
@RequestMapping("/basedata/report")
public class BaseReportController extends BaseController
{
    private static final Logger log = LoggerFactory.getLogger(BaseReportController.class);
    
    private String prefix = "basedata/report";

    @Autowired
    private IBaseReportService baseReportService;

    /**
     * 商品单价统计报表页面
     */
    @RequiresPermissions("basedata:report:productCount")
    @GetMapping("/productCount")
    public String productCount()
    {
        return prefix + "/productCount";
    }

    /**
     * 查询商品名称和单价统计数据
     */
    @RequiresPermissions("basedata:report:productCount")
    @PostMapping("/getProductCountData")
    @ResponseBody
    public AjaxResult getProductCountData()
    {
        try {
            List<Map<String, Object>> data = baseReportService.selectProductCountData();
            return AjaxResult.success(data);
        } catch (Exception e) {
            log.error("获取商品统计数据出错", e);
            return AjaxResult.error("获取数据失败，请联系管理员");
        }
    }
    
    /**
     * 查询商品采购量和销售量数据
     */
    @RequiresPermissions("basedata:report:productCount")
    @PostMapping("/getProductVolumeData")
    @ResponseBody
    public AjaxResult getProductVolumeData()
    {
        try {
            List<Map<String, Object>> data = baseReportService.selectProductVolumeData();
            return AjaxResult.success(data);
        } catch (Exception e) {
            log.error("获取商品采购量和销售量数据出错", e);
            return AjaxResult.error("获取数据失败，请联系管理员");
        }
    }
} 